package gameFight;

/**
 * 作者:TC
 * 时间:基础角色B类 18:08
 * 描述:没有bug
 */
// 定义角色B类，继承自基础角色类
public class RoleB extends Role {
    private int experience;  // 经验值
    private int level;  // 等级

    public RoleB(int health, int attack, int defense, double critRate, double shieldRate,
                 int experience, int level) {
        super(health, attack, defense, critRate, shieldRate);
        this.experience = experience;
        this.level = level;
    }
//B胜利的奖励机制
    public void win()
    {
        reward reB=new reward(0.3,0.7);
         //调用获取奖励
        String rewB=reB.giveReward();
        //经验值相加
        this.experience += reB.getExp();
        System.out.print(" ---B获得的奖励:"+rewB);
        System.out.print(" ---B获得的经验值:"+reB.getExp());
        System.out.print(" ---B当前的经验值:"+this.experience);
    }
    //重写roleB的攻击和防御触发暴击的方法
    // 计算角色B的实际攻击力
    @Override
    public int calculateAttack() {
        if (Math.random() >= critRate) {
            return (int) (getAttack() * 1.3);  // 角色B的攻击力暴击系数为1.3
        } else {
            return getAttack();
        }
    }

    // 角色B受击时计算实际防御力
    @Override
    public int calculateDefense() {
        if (Math.random() >= shieldRate) {
            return (int)(getDefense() *2);  // 角色B的防御力额外增加15点
        } else {
            return getDefense();
        }
    }
    public int getExperience() {
        return experience;
    }

    public void setExperience(int experience) {
        this.experience = experience;
    }

    public int getLevel() {
        return level;
    }

    public void setLevel(int level) {
        this.level = level;
    }
}